layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
    $.get("/js/json/sign.json",function(data){
        var iconHtml = '';
        for(var i=0;i<data.length;i++){
            iconHtml+=' <li>\
                <i class="layui-icon">'+data[i].icon+'</i>\
            <div class="name">'+data[i].name+'</div>\
                <div class="code">'+data[i].sign+'</div>\
            </li>';
        }
        $(".site-doc-icon").html(iconHtml);
    },"json");

    form.on("submit(btnSubmit)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        $.post("/baseMenu/UpdateOrAddEntity",{
            menuname : $(".menuname").val(),  //菜单名称
            menusign : $(".menusign").val(),  //菜单图标
            menuurl : $(".menuurl").val(),  //菜单连接
            menunum : $(".menunum").val(),  //菜单排序
            menuid : $(".menuid").val(),  //菜单id
            parentmenuid : $(".parentmenuid").val(),  //菜单父类id
        },function(result){
            if(1==result.returnInfo.state){
                top.layer.close(index);
                top.layer.msg("操作成功！");
                layer.closeAll("iframe");
                //刷新父页面
                parent.location.reload();
            }else{
                top.layer.msg(result.returnInfo.errorMsg);
            }
        },"json")
        return false;
    });
    $("#signBtn").click(function(){
        var str="";
        var num=1;
        $("#sign ul li").each(function (index,obj) {
            if(num!=1){
                str+=',';
            }
            str+='{"num": '+num+',"icon": "'+$(obj).find(".code").html().replace("amp;","")+'","sign": "'+$(obj).find(".code").html()+'", "name": "'+$(obj).find(".name").html()+'"}';
            num++;
        });
        $("#signs").val(str);
    })
})